/*
Author: Ihab Ali                   
email :ali00173@algonquinlive.
IPV4Caluclator/ 8th Feb 2014
*/

package controller;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.CalculatorIPV4Model;

/**
 * 
 * The class creates two models one for the Brief page another for the details page 
 * Also responsible for linking the two models if the user chooses this in the option page
 * @author Ihab Ali
 * @version 1.1
 */
@ManagedBean(name = "controller")
@SessionScoped
public class CalculatorIPV4Controller implements Serializable {

    private CalculatorIPV4Model brief_model;
    private CalculatorIPV4Model detail_model;
    private boolean linked;
    private final long serialVersionUID = -3377875199072595764L;
    
    /**
     * Creates two different models and sets the default octet values of each model
     */
    public  CalculatorIPV4Controller() {
        super();
        
        detail_model = new CalculatorIPV4Model(192, 168, 254, 254, 24);
        detail_model.doCalculations();
        
        brief_model = new CalculatorIPV4Model(192, 168, 254, 254, 24);
        brief_model.doCalculations();
    }
    
    
    public void setLinked(boolean linkedpram) {
        this.linked = linkedpram;
    }
    
    /**
     * Getter the brief model 
     * @return if linked  detail_model will be returned 
     */
    public CalculatorIPV4Model getBrief_model() {
        if (!linked)
            return brief_model;
        
        else
            return detail_model;
        
    }
    /**
     * Getter for  the detail model
     * @return detail_model
     */
    public CalculatorIPV4Model getDetail_model() {
        return detail_model;
    }
    /**
     * 
     * @return true or false 
     */
    public boolean isLinked(){
        return linked;
    }
    
    /**
     * setter to the  brief model
     * @param model
     */
    public void setBrief_model(CalculatorIPV4Model model) {
        this.brief_model = model;
    }
    /**
     * Setter to the detail model
     * @param model
     */
    public void setDetail_model(CalculatorIPV4Model model) {
        this.detail_model = model;
    }
    
   



    /**
     * Performs calculation based on if the models are linked together
     */
    public void doCalculateBriefInfo() {
        if (!linked){
            brief_model.doCalculations();
        }
        else{
            detail_model.doCalculations();
        }
    }
    /**
     * calls the dCalculations method for the detail model 
     */
    public void doCalculateDetailedInfo() {
            detail_model.doCalculations();
    }
}
